package com.bjyhl.app;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.bjyhl.core.activities.ProxyActivity;
import com.bjyhl.core.app.Latte;
import com.bjyhl.core.fragments.LatteFragment;
import com.bjyhl.medical.bean.event.MessageEvent;
import com.bjyhl.medical.launcher.LauncherFragment;
import com.bjyhl.medical.main.EcBottomFragment;
import com.bjyhl.medical.sign.ISignListener;
import com.bjyhl.medical.test.upload.TestUploadFragment;
import com.bjyhl.ui.launcher.ILauncherListener;
import com.bjyhl.ui.launcher.OnLauncherFinishTag;

import org.greenrobot.eventbus.EventBus;

import cn.jpush.android.api.JPushInterface;
import me.yokeyword.eventbusactivityscope.EventBusActivityScope;
import qiu.niorgai.StatusBarCompat;

public class MainActivity extends ProxyActivity implements
        ISignListener, ILauncherListener {

    private final int APP_INIT=12138;
    private final Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case APP_INIT:
                    EventBusActivityScope.getDefault(getActivity()).post(new MessageEvent<String>(MessageEvent.Type.CALL_TYPE, "新电影哈哈"));
                    break;
            }
            return false;
        }
    });

    private MainActivity getActivity(){
        return this;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Latte.getConfigurator().withActivity(this);
        StatusBarCompat.translucentStatusBar(this, true);

        // TODO 测试移除
        handler.sendEmptyMessageDelayed(APP_INIT, 20000);
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }

    @Override
    public LatteFragment setRootFragment() {
//        return new TestUploadFragment();
        return new EcBottomFragment();
//        return new LauncherFragment();

//        return new TestPubuFragment();
//        return new TestFragment();
    }

    @Override
    public void onSignInSuccess() {
        Toast.makeText(this, "登录成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onSignUpSuccess() {
        Toast.makeText(this, "注册成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onLauncherFinish(OnLauncherFinishTag tag) {
        switch (tag) {
            case SIGNED:
//                Toast.makeText(this, "您已登陆了哟！", Toast.LENGTH_LONG).show();
                getSupportDelegate().startWithPop(new EcBottomFragment());
                break;
            case NOT_SIGNED:
                Toast.makeText(this, "亲，您还没有登录！", Toast.LENGTH_LONG).show();
                getSupportDelegate().startWithPop(new EcBottomFragment());
                break;
            default:
                break;
        }
    }
}
